<template>
  <div>
    <input type="text" v-model="loginInfo.mobile">
    <input type="password" v-model="loginInfo.pwd">
    <button @click="userLogin">登录</button>
    <router-link to="/register">还没有账号? 立即注册</router-link>
 </div>
</template>

<script>
import { login, getUserInfo } from '@/api/profile'
export default {
  name: '',
  data() { 
    return {
      loginInfo: {
        mobile: '',
        pwd: ''
      }
    }
  },
  methods:{
    userLogin() {
      login(this.loginInfo).then(res => {
        // console.log(res);
        this.$store.commit('saveUserInfo' ,res.data)
        getUserInfo(res.data.token).then(res => {
          // console.log(res);
          localStorage.setItem('user', JSON.stringify(res.data))
        })
      })
    }
  },
 }
</script>

<style scoped>
</style>